<template>
	<view>
		<u-toast ref="uToast" /><u-no-network></u-no-network>
		<u-navbar title="销售员列表" safeAreaInsetTop fixed placeholder>
		    <view class="coreshop-navbar-left-slot" slot="left">
		        <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
		        <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
		        <u-icon name="home" size="22" @click="goHome"></u-icon>
		    </view>
		    <view slot="right">
		    </view>
		</u-navbar>
		<view class="content">
			<view class="coreshop-padding-10 coreshop-margin-bottom-5 coreshop-bg-white coreshop-solid-bottom">
			    <u-search placeholder="请输入关键字搜索" v-model="key" :show-action="true" action-text="搜索" :animation="false" @custom="doSearch()"></u-search>
			</view>
			<scroll-view class="scroll-box" scroll-y>
				<view v-if="list.length">
					<view class="item  coreshop-display-flex coreshop-flex-nowrap coreshop-justify-between" v-for="(item, key) in list" :key="key">
						<view>
							<view class="top">
								<view class="name">{{ item.name }}</view>
								<view class="phone">{{ item.mobile }}</view>
							<!-- <view class="tag">
									<text class="red" v-if="item.isDefault">默认</text>
								</view> -->
							</view>
							<view class="bottom">
								<view>备注：{{item.remark || ''}}</view> 
								<view class="child-num coreshop-margin-left-30">订单数：({{ item.orderNum || 0 }})</view> 
							</view>
						</view>
						<view class="coreshop-display-flex coreshop-flex-direction c-m-t-20">
							<u-icon name="edit-pen-fill" :size="20" color="#3191fd" @click="toEdit(item)"></u-icon> 
						</view>
						<view class="c-m-t-20" @click="goOrder(item.userId,item.name)" v-if="item.orderNum > 0">
							<u-image src="/static/images/icon/arrow.png" width="15" height="15" :lazy-load="false"
							:show-loading="false" :fade="false"></u-image>
						</view>
					</view>
					<!-- 更多 -->
					<u-loadmore :status="loadStatus" :icon-type="iconType" :load-text="loadText" margin-top="20" margin-bottom="20" />
				</view>
				<!-- 无数据时默认显示 -->
				<view class="coreshop-emptybox" v-else>
					<u-empty :icon="$globalConstVars.apiFilesUrl+'/static/images/empty/address.png'" icon-size="150" text="暂无信息" mode="list"></u-empty>
				</view>
			</scroll-view>
			
			<!--按钮--> 
			<view class="floatingButton" @click="toAdd"> 
				 <u-icon name="plus-circle-fill" color="#e54d42" size="45"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
		    return {
		        list: [],// 列表 
				loadStatus: 'loadmore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
				iconType: 'flower',
				loadText: {
				    loadmore: '轻轻上拉',
				    loading: '努力加载中',
				    nomore: '实在没有了'
				},
				currentPage: 1, 
				key: '',
				searchData: {
					id:null,
				    where: {},
				    limit: 10,
				    page: 1 
				},
		    }
		},
		onShow() {
			this.currentPage=1;
			this.list=[];
			this.getAgentPageList();
		},
		onReachBottom() {// 加载更多
		    if (this.loadStatus === 'loadmore') {
		        this.getAgentPageList()
		    }
		},
		//加载执行
		onLoad: function (options) {
		},
		methods:{ 
			//获取列表
			getAgentPageList(){
				let self=this;
				 
				this.loadStatus = 'loading';
				this.$u.api.getAgentPageList(this.conditions()).then(res => {
				    if (res.status) {
				        let _list = res.data;
						self.list = [...self.list, ..._list] ;
						if (res.code > self.list.length) {
						    self.currentPage++
						    self.loadStatus = 'loadmore'
						} else {
						    self.loadStatus = 'nomore'
						}
				    }
				})
			},
			//添加
			toAdd() {
			    this.$u.route('/pages/member/dealer/salesperson/index/index');
			},
			//编辑
			toEdit(item) {
				let store=item;
			    this.$u.route('/pages/member/dealer/salesperson/index/index?store=' + JSON.stringify(store));
			},
			//搜索
			doSearch() {
				this.currentPage=1;
				this.list=[];
				this.getAgentPageList();
			},
			// 统一返回筛选条件 查询条件 分页
			conditions() {
				var where = {};
				if(this.key != ''){
					where = {
					    searchName: this.key
					};
				}
				this.searchData.where = where; 
				this.searchData.page = this.currentPage;
				
			    let data = this.searchData;
			    var newData = this.$u.deepClone(data);
			    if (data.where) {
			        newData.where = JSON.stringify(data.where);
			    } 
			    return newData;
			},
			goOrder(userId,name){
				this.$u.route('/pages/member/dealer/agentOrder/agentOrder',{
					userId:userId,
					title:`${name}的订单`
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item { padding: 20px; background: #fff; margin: 5px 10px;border-radius:8px;
	    .top { display: flex; font-weight: bold; font-size: 17px;
	        .phone { margin-left: 30px; }
	        .tag { display: flex; font-weight: normal; align-items: center;
	            text { display: block; width: 30px; height: 17px; line-height: 17px; color: #ffffff; font-size: 10px; border-radius: 3px; text-align: center; margin-left: 15px; background-color: #3191fd; }
	            .red { background-color: red; }
	        }
	    }
	    .bottom { display: flex; margin-top: 10px; font-size: 14px; justify-content: space-between; color: #999999; }
	}
</style>